﻿using System;
using System.Linq;
using System.Collections.Generic;
using T.FAS.Runtime.Metadata.Entity.DataModel;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    /// <summary>
    /// InternationalTools
    /// </summary>
    public class InternationalTools
    {
        /// <summary>
        /// 是否将连字符转换为下划线
        /// </summary>
        public static bool IsConvertHyphenToUnderline = true;

        /// <summary>
        /// 获取国际化列的对应语言辅助列列名，用于TRecord中的多语言字段 例如 Name_en_US
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="i18NCode"></param>
        /// <returns></returns>
        public static string GetLogicFieldName(string columnName, string i18NCode)
        {
            if (IsConvertHyphenToUnderline)
                i18NCode = i18NCode.Replace('-', '_');
            return $"{columnName}_{i18NCode}";
        }

        /// <summary>
        /// 获取国际化列的对应语言辅助列列名后缀，用于从ChangeSetItem中反向提取字段
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="i18NCode"></param>
        /// <returns></returns>
        public static string GetLogicFieldNameSuffix(string i18NCode)
        {
            if (IsConvertHyphenToUnderline)
                i18NCode = i18NCode.Replace('-', '_');
            return $"_{i18NCode}";
        }  
    }
}
